#!/usr/bin/python

import roslib; roslib.load_manifest('framer')
import rospy

from cv_bridge import CvBridge, CvBridgeError
import cv

#code.ros.org/trac/opencv/browser/trunk/opencv/samples/python/houghlines.py?rev=731
class BackgroundProcessor():
   def __init__(self, thresh = 45, standard = True):
      self.threshold = int(thresh)
      self.standard  = True

   def process(self, image):  # Pass in a cv image
      # not sure which one would be more useful
      edge_image = cv.CreateMat(image.rows, image.cols, cv.CV_8UC1)
      cv.Canny(image, edge_image, 50, 100)
      hough_type = cv.CV_HOUGH_STANDARD
      if not self.standard:
         hough_type = cv.CV_HOUGH_PROBABILISTIC
      lines = cv.HoughLines2( edge_image, cv.CreateMemStorage(0), hough_type, 1, cv.CV_PI/180, 100, 0, 0)  # Finds lines
      rospy.loginfo("Found {0} lines in background".format(len(lines)))
      if (len(lines) > self.threshold):
         return "busy"
      return "not busy"
